on public_factorial_1
on fact me, n
  if n=0 then return 1
  else return n*me.factorial[n-1]
end

on public_factorialCPS_2
on fac me, n,k
  x = LingoF().var()
  if ( n = 0 ) then return k [1] 
  else return me.factorialCPS[$(#-,n,1) ] [ LingoF().fun(x) [ k [ $(#*,n,x) ]  ] ]
end


on public_rec_1
on recur me, f
  a = LingoF().Var()
  r = LingoF().Var()
  rc = LingoF().fun(r,a)  [ f[r[r]] [a] ]
  return rc[rc]
end

on public_Just_1
on Just me, v
  return [v]
end

on public_IsNothing_1
on IsNothing me, v
  return not v.count()
end

on public_Skip_1
on Skip me, f
  return f.skip()
end

on public_Apply_2
on Apply me, x,y
  return x[y]
end

on public_Flip_3
on Flip me, f,x,y
  return f[y][x]
end

on public_ReverseCompose_3
on ReverseCompose me, g,f,x
  return f[g[x]]
end

on public_Compose_3
on Compose me, f,g,x
  return f[g[x]]
end

on public_ifThenElse_3
on ifThenElse me, condition,positiveValue,negativeValue
  if condition then return positiveValue
  else return negativeValue
end

on public_ID_1
on id me, x
  return x
end

on public_compareWith_3
on compareWith me, fn,x,y
  if fn[x]<fn[y] then return -1
  else return not (fn[x]=fn[y])
end